package com.edu.edu.day25_homework.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.edu.edu.day25_homework.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * A simple {@link Fragment} subclass.
 */
public class MeFragment extends Fragment {


    public MeFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_me, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ListView mLv = (ListView)view.findViewById(R.id.login_list);
        ImageView image = (ImageView)view.findViewById(R.id.me_image);
        TranslateAnimation ta = new TranslateAnimation(0, 100,0,-100);
        ta.setDuration(4000);
        ta.setRepeatCount(100);
        ta.setRepeatMode(Animation.REVERSE);
        image.startAnimation(ta);

        List<Map<String,Object>> data = new ArrayList<>();
        String[] name = getResources().getStringArray(R.array.logo);
        int[] imagesId = getImagesId();
        for (int i = 0; i <name.length; i++) {
            Map<String,Object> map = new HashMap<>();
            map.put("images",imagesId[i]);
            map.put("text",name[i]);
            data.add(map);
        }

        SimpleAdapter adapter = new SimpleAdapter(getActivity(),data,R.layout.login_list_item,new String[]{"images","text"},new int[]{R.id.login_image,R.id.login_text});

        mLv.setAdapter(adapter);
    }

    public int[] getImagesId() {
        return new int[]{R.mipmap.notification_icon,R.mipmap.notification_show_icon,R.mipmap.icon_shop_order,R.mipmap.icon_my_home_hongbao,R.mipmap.icon_my_home_presell,R.mipmap.icon_my_home_vip_code_exchange,R.mipmap.icon_my_home_watch_trajectory,R.mipmap.icon_my_home_setting};
    }
}
